/*
 * comm_std.h
 *
 *  Created on: 2010-1-7
 *      Author: gavinkwoe
 */

#ifndef COMM_STD_H_
#define COMM_STD_H_

#include "cx_predef.h"
#include "cx_typedef.h"
#include "cx_string.h"

/*************************************************************************
* MACRO
*************************************************************************/

#define COMM_ERR_REASON_UNKNOWN				(0)
#define COMM_ERR_REASON_NOT_FOUND				(1)
#define COMM_ERR_REASON_FILE_BROKEN			(2)
#define COMM_ERR_REASON_INVALID_PARAM			(3)
#define COMM_ERR_REASON_OUT_OF_MEMORY			(4)
#define COMM_ERR_REASON_DLL_INTERNAL			(5)
#define COMM_ERR_REASON_OPEN_FILE				(6)
#define COMM_ERR_REASON_READ_FILE				(7)
#define COMM_ERR_REASON_FILE_TOO_SHORT			(8)
#define COMM_ERR_REASON_ENCODING_NOT_SUPPORT	(9)

// Text add-on DLL
#define COMM_ERR_REASON_TXT_OUT_OF_RANGE		(100 + 1)
#define COMM_ERR_REASON_TXT_BUILD_CACHE		(100 + 2)

/*************************************************************************
* MACRO
*************************************************************************/

#ifndef NULL
#define NULL							(0)
#endif	// #ifndef NULL

#ifndef MAX_PATH
#define MAX_PATH						(512)
#endif	// #ifndef MAX_PATH

#define	TMP
#define	OUT
#define	IN
#define	INOUT

#define COMM_TRUE						(0)
#define COMM_FALSE						(1)

#define COMM_OK						(0)
#define COMM_FAILED					(1)
#define COMM_NONSUPPORT				(2)

#define COMM_UNUSED( __x )				((void)__x)
#define COMM_ASSERT( __x )				

#define COMM_PROC						*
#define COMM_FAR_PROC					*

#define	COMM_INVOKE( __fp, __pl )		( * __fp ) __pl

#define COMM_ROUND_UP_2( __x )			(((__x + 1) >> 1) << 1)
#define COMM_ROUND_UP_4( __x )			(((__x + 3) >> 2) << 2)

#define COMM_IMPORT					IMPORT_C
#define COMM_EXPORT					EXPORT_C

#define __CASE( __a, __b )				if ( 0 == cx_strcmp_a((const char *)__a, (const char *)__b) )
#define __ELSE_CASE( __a, __b )			else __CASE( __a, __b )
#define __ELSE							else

#define	COMM_SIZEOF_ARRAY( __a )		( sizeof(__a) / sizeof(__a[0]) )
#define COMM_UNUSED( __x )				((void)__x)

#define	COMM_OFFSET_OF( __s, __m )			(unsigned long)( (char *)(&((__s *)0)->__m) - (char *)((__s *)0) )
#define COMM_CONTAINER_OF( __p, __s, __m )	((char *)__p - COMM_OFFSET_OF(__s, __m))

/*************************************************************************
* TYPE
*************************************************************************/

typedef	unsigned char *					comm_guid_t;
typedef int ( COMM_PROC comm_cmp_fptr_t )( const void * lhs, const void * rhs );

/*************************************************************************
* PROTOTYPE
*************************************************************************/

struct __struct_comm_rect;
typedef struct __struct_comm_rect		comm_rect_t;
typedef struct __struct_comm_rect *	comm_rect_ptr_t;

struct __struct_comm_color;
typedef struct __struct_comm_color		comm_color_t;
typedef struct __struct_comm_color *	comm_color_ptr_t;

/*************************************************************************
* STRUCTURE
*************************************************************************/

struct __struct_comm_rect
{
	signed long		x;
	signed long		y;
	unsigned long	w;
	unsigned long	h;
};

struct __struct_comm_color
{
	unsigned char	a;
	unsigned char	r;
	unsigned char	g;
	unsigned char	b;
};

/*************************************************************************
* EXPORTED FUNCTION
*************************************************************************/

COMM_IMPORT unsigned long	comm_cmp_guid( comm_guid_t lhs, comm_guid_t rhs );

#endif /* COMM_STD_H_ */
